$(function () {
	//修改车位
	$("#btn_carportUpdate").on("click", function(){
		var carportId = $("input[name='carportId']").val();
		var parentName = $("input[name='parentName']").val();
		carportUpdate(carportId, parentName);
	});
	
	//删除车位
	$("#btn_carportDel").on("click", function(){
		var carportId = $("input[name='carportId']").val();
		del(carportId);
	});
	
	
});

//车位修改弹出层
function carportUpdate(carportId, parentName){
	JY.Ajax.doRequest(null,jypath+'/estate/projectCarport/view',{id:carportId},function(data){
		setCarportForm(data);
		$("#carportForm label[name='parentName']").text(parentName);
    	save("编辑车位","/estate/projectCarport/edit", carportId);
	});
}

function save(title, url, id){
	JY.Model.edit("carportDiv",title,function(){
		if(JY.Validate.form("carportForm")){
			var that =$(this);
			JY.Ajax.doRequest("carportForm",jypath +url,null,function(data){
				that.dialog("close");
	        	JY.Model.info(data.resMsg,function(){
	        		var url = jypath + "/estate/projectCarport/detail?id="+id;
	        		$.post(url, null, function(data){
	        			$("#rightContentDiv").html(data);
	        		});
        		});    
			 });
		}	
	});
}

function del(id){
	JY.Model.confirm("该操作将删除车位,是否确认删除？",function(){
		JY.Ajax.doRequest(null,jypath+'/estate/projectCarport/delete',{id:id},function(data){
			JY.Model.info(data.resMsg,function(){
				$("#rightContentDiv").html("");
 				if(data.res == 1){
 	 				deleteNode();
 	 			}
			});
		});
	});
}

function setCarportForm(data){
	var obj = data.obj;
	$("#carportForm input[name$='id']").val(JY.Object.notEmpty(obj.id));
	$("#carportForm input[name$='carportName']").val(JY.Object.notEmpty(obj.carportName));
	$("#carportForm input[name$='sort']").val(JY.Object.notEmpty(obj.sort));
	$("#carportForm input[name$='propertyType']").val(JY.Object.notEmpty(obj.propertyType));
	$("#carportForm input[name$='carportSalesStatus']").val(JY.Object.notEmpty(obj.carportSalesStatus));
	$("#carportForm textarea[name$='remark']").val(JY.Object.notEmpty(obj.remark));
}

